import java.io.IOException;
import java.io.Serializable;
import java.util.logging.*;

/**
 * Base User object class. Used for creating and adding new users to the system.
 * @author Michael Zipp
 *
 */
public class User implements Serializable{
	String name;

	String username;
	
	String password;
	
	String address;
	
	String phoneNum;
	
	String email;
	
	String age;
	
	boolean locked;
	
	int lockCounter;
	
	public String usertype;
	
	private static Logger userLog = Logger.getLogger(User.class.getName());
	
	static{
		ConsoleHandler console = new ConsoleHandler();
		console.setLevel(Level.ALL);
		console.setFormatter(new ThunderDragonHtmlFormatter());
		userLog.addHandler(console);
		userLog.setLevel(Level.ALL);
		
		try {
			FileHandler fh = new FileHandler("UserLogger.txt");
			fh.setFormatter(new ThunderDragonHtmlFormatter());
			userLog.addHandler(fh);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			userLog.severe("Failure: Security exception thrown " +
					"when trying to create a new handler" +
					" in User.java.");
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			userLog.severe("Failure: I/O exception thrown" +
					" when trying to create a new handler" +
					" in User.java.");
			e.printStackTrace();
		}
		
	}
	
	/**
	 * This constructor creates a new User for the system. 
	 * @param name Full name of the user
	 * @param username The new user's username to log in with
	 * @param password The password the user logs in with
	 * @param address The full address of the User
	 * @param phoneNum Phone number of the user (no dashes)
	 * @param email Email account of the user
	 * @param age Age of the user.
	 */
	public User(String name, String username, String password, 
			String address, String phoneNum, String email, String age){
		
		userLog.entering(this.getClass().getName(),
				"User Constructor", new Object[] {name, username, password,
			address, phoneNum, email, age});
	
		this.name = name;
		this.username = username;
		this.password = password;
		this.address = address;
		this.phoneNum = phoneNum;
		this.email = email;
		this.age = age;
		locked = false;
		lockCounter = 0;
		
		userLog.exiting(this.getClass().getName(), "User Constructor");
	}
	
	public User() {
		
		userLog.entering(this.getClass().getName(), "User Default Constructor");
		userLog.exiting(this.getClass().getName(), "User Defualt Constructor");
		
	}

	/**
	 * Returns the user itself, as to be displayed by another class
	 * @return the user
	 */
	User viewUser(){
		userLog.finest("Called viewUser() in class User.");
		return this;
	}
	
	/**
	 * Returns whether the account is locked or not.
	 * @return boolean representing locked.
	 */
	public boolean isLocked(){
		userLog.finest("Called isLocked() in class User.");
		return locked;
	}
	
	/**
	 * Makes changes to the User based on the input
	 * @param a Changed user
	 */
	void editUser(User a){
		name = a.getName();
		password = a.getPassword();
		address = a.getAddress();
		phoneNum = a.getPhoneNum();
		email = a.getEmail();
		age = a.getAge();
		userLog.finest("Called editUser() in class User.");
	}

	/**
	 * @return the name
	 */
	String getName() {
		userLog.finest("Called getName() in class User.");
		return name;
	}

	/**
	 * @param name the name to set
	 */
	void setName(String name) {
		this.name = name;
		userLog.finest("Called setName() in class User.");
	}

	/**
	 * @return the username
	 */
	String getUsername() {
		userLog.finest("Called getUsername() in class User.");
		return username;
	}

	/**
	 * @param username the username to set
	 */
	void setUsername(String username) {
		this.username = username;
		userLog.finest("Called setUsername() in class User.");
	}

	/**
	 * @return the password
	 */
	String getPassword() {
		userLog.finest("Called getPassword() in class User.");
		return password;
	}

	/**
	 * @param password the password to set
	 */
	void setPassword(String password) {
		this.password = password;
		userLog.finest("Called setPassword() in class User.");
	}

	/**
	 * @return the address
	 */
	String getAddress() {
		userLog.finest("Called getAddress() in class User.");
		return address;
	}

	/**
	 * @param address the address to set
	 */
	void setAddress(String address) {
		this.address = address;
		userLog.finest("Called setAddress() in class User.");
	}

	/**
	 * @return the phoneNum
	 */
	String getPhoneNum() {
		userLog.finest("Called getPhoneNum() in class User.");
		return phoneNum;
	}

	/**
	 * @param phoneNum the phoneNum to set
	 */
	void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
		userLog.finest("Called setPhoneNum() in class User.");

	}

	/**
	 * @return the email
	 */
	String getEmail() {
		userLog.finest("Called getEmail() in class User.");
		return email;
	}

	/**
	 * @param email the email to set
	 */
	void setEmail(String email) {
		this.email = email;
		userLog.finest("Called setEmail() in class User.");

	}

	/**
	 * @return the age
	 */
	String getAge() {
		userLog.finest("Called getAge() in class User.");
		return age;
	}

	/**
	 * @param age the age to set
	 */
	void setAge(String age) {
		this.age = age;
		userLog.finest("Called setAge() in class User.");
	}

	@Override
	public String toString() {
		return "User [name=" + name + ", username=" + username + ", password="
				+ password + ", address=" + address + ", phoneNum=" + phoneNum
				+ ", email=" + email + ", age=" + age + ", locked=" + locked
				+ ", lockCounter=" + lockCounter + ", usertype=" + usertype
				+ "]";
	}
	
	
}
